package com.jpcc.vw.onlineRadio.adapter.item;

import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jpcc.vw.onlineRadio.R;
import com.jpcc.vw.onlineRadio.model.action.OnlineRadioItemSelectedAction;
import com.jpcc.vw.onlineRadio.model.bean.OnlineRadioSimpleInfoEntity;
import com.jpcc.vw.onlineRadio.recycle.RecyclerView.BaseItem;
import com.jpcc.vw.onlineRadio.service.AlbumRadioAudioPlayer;

import de.greenrobot.event.EventBus;


/**
 * Created by jihongwen on 16/6/30.
 */

public class SimpleOnlineRadioInfoItem extends BaseItem<OnlineRadioSimpleInfoEntity> implements View.OnClickListener {

    private OnlineRadioSimpleInfoEntity resultsBean;
    private TextView tv_item_count;
    private TextView tv_content2;
    private TextView tv_content3;
    private ImageView imv_delete;
    private ImageView imv_download;
    private RelativeLayout layout_top;

    public SimpleOnlineRadioInfoItem(ViewGroup parent) {
        super(parent);
    }

    @Override
    public int getRes() {
        return R.layout.adapter_album_radio_item;
    }

    @Override
    public void onCreateView(View rootView) {
        tv_item_count = (TextView) rootView.findViewById(R.id.tv_item_count);
        tv_content2 = (TextView) rootView.findViewById(R.id.tv_content2);
        tv_content3 = (TextView) rootView.findViewById(R.id.tv_content3);
        imv_delete = (ImageView) rootView.findViewById(R.id.imv_delete);
        imv_download = (ImageView) rootView.findViewById(R.id.imv_delete);
        layout_top = (RelativeLayout) rootView.findViewById(R.id.layout_top);
    }

    @Override
    public void onBindView(final OnlineRadioSimpleInfoEntity response) {
        this.resultsBean = response;
        tv_item_count.setText(getPosition() + "");
        tv_content2.setText(resultsBean.getRadioName());
        if(AlbumRadioAudioPlayer.get().getPlayMusic()==null){
            layout_top.setBackgroundColor(Color.parseColor("#0e0e0e"));
        }
        else{
            if (AlbumRadioAudioPlayer.get().getPlayMusic().getTrackId() == resultsBean.getId()) {
                layout_top.setBackgroundColor(Color.parseColor("#4600b2fb"));
            }
            else{
                layout_top.setBackgroundColor(Color.parseColor("#0e0e0e"));
            }
        }
    }

    @Override
    public void onClick(View v) {
        OnlineRadioItemSelectedAction action = new OnlineRadioItemSelectedAction();
        action.setPosition(getPosition());
        EventBus.getDefault().post(action);
    }
}
